require 'enum'
require 'singleton'
require 'merge/field'
require 'merge/simple_field'
require 'merge/multiple_field'
require 'amatch'

include Amatch

module Merge
  
  class Fields < Enum
    
    include Singleton
    
    public
    
    class FullName < SimpleField
      def name
        "full_name"  
      end   
      
      protected
      
      def sim(a,b)
        return 0.99 if a.kind_of?(Symbol) || b.kind_of?(Symbol)
        a.hamming_similar b
      end
    end
    
    class FirstName < SimpleField
      def name
        "first_name"  
      end   
      
      protected
      
      def sim(a,b)
        return 0.99 if a.kind_of?(Symbol) || b.kind_of?(Symbol)
        a.hamming_similar b
      end
    end
    
    class LastName < SimpleField
      def name
        "last_name"  
      end   
      
      protected
      
      def sim(a,b)
        return 0.99 if a.kind_of?(Symbol) || b.kind_of?(Symbol)
        a.hamming_similar b
      end
    end
    
    class Gender < SimpleField
      def name
        "gender"  
      end   
      
      protected
      
      def sim(a,b)
        return 0.99 if a.kind_of?(Symbol) || b.kind_of?(Symbol)
        a.eql?(b) ? 1.0 : 0.0
      end
    end
    
    class Age < SimpleField
      def name
        "age"  
      end   
      
      protected
      
      def sim(a,b)
        return 0.99 if a.kind_of?(Symbol) || b.kind_of?(Symbol)
        1.0 - (a.to_f - b.to_f).abs / [a.to_f,b.to_f].max
      end
    end
    
    class RelStatus < SimpleField
      def name
        "rel_status"  
      end   
      
      protected
      
      def sim(a,b)
        return 0.99 if a.kind_of?(Symbol) || b.kind_of?(Symbol)
        a.eql?(b) ? 1.0 : 0.0
      end
    end
    
    class Lang < SimpleField
      def name
        "locale_language"  
      end   
      
      protected
      
      def sim(a,b)
        return 0.99 if a.kind_of?(Symbol) || b.kind_of?(Symbol)
        a.eql?(b) ? 1.0 : 0.0
      end
    end
    
    class Email < SimpleField
      def name
        "email"  
      end   
      
      protected
      
      def sim(a,b)
        return 0.99 if a.kind_of?(Symbol) || b.kind_of?(Symbol)
        a.hamming_similar b
      end
    end
    
    class Occupation < SimpleField
      def name
        "occupation"  
      end   
      
      protected
      
      def sim(a,b)
        return 0.99 if a.kind_of?(Symbol) || b.kind_of?(Symbol)
        a.hamming_similar b
      end
    end
    
    class Role < SimpleField
      def name
        "role"  
      end   
      
      protected
      
      def sim(a,b)
        return 0.99 if a.kind_of?(Symbol) || b.kind_of?(Symbol)
        a.hamming_similar b
      end
    end
    
    class FullLocation < SimpleField
      def name
        "full_location"
      end   
      
      protected
      
      def sim(a,b)
        return 0.99 if a.kind_of?(Symbol) || b.kind_of?(Symbol)
        a.hamming_similar b
      end
    end
    
    class Locality < SimpleField
      def name
        "locality"
      end   
      
      protected
      
      def sim(a,b)
        return 0.99 if a.kind_of?(Symbol) || b.kind_of?(Symbol)
        a.hamming_similar b
      end
    end
    
    class State < SimpleField
      def name
        "state"
      end   
      
      protected
      
      def sim(a,b)
        return 0.99 if a.kind_of?(Symbol) || b.kind_of?(Symbol)
        a.hamming_similar b
      end
    end 
    
    class Country < SimpleField
      def name
        "country"
      end   
      
      protected
      
      def sim(a,b)
        return 0.99 if a.kind_of?(Symbol) || b.kind_of?(Symbol)
        a.hamming_similar b
      end
    end
    
    class LocaleCountry < SimpleField
      def name
        "locale_country"
      end   
      
      protected
      
      def sim(a,b)
        return 0.99 if a.kind_of?(Symbol) || b.kind_of?(Symbol)
        a.hamming_similar b
      end
    end
    
    class FullHometown < SimpleField
      def name
        "full_hometown"
      end   
      
      protected
      
      def sim(a,b)
        return 0.99 if a.kind_of?(Symbol) || b.kind_of?(Symbol)
        a.hamming_similar b
      end
    end
    
    class Music < MultipleField
      def name
        "music"
      end   
    end
    
    class Movies < MultipleField
      def name
        "movies"
      end   
    end
    
    class Interests < MultipleField
      def name
        "interests"
      end   
    end
    
    class Books < MultipleField
      def name
        "books"
      end   
    end
    
    protected
    
    def initialize
      super()
      @collections["full_name"] = FullName.instance
      @collections["first_name"] = FirstName.instance
      @collections["last_name"] = LastName.instance
      @collections["gender"] = Gender.instance
      @collections["age"] = Age.instance
      @collections["lang"] = Lang.instance
      @collections["rel_status"] = RelStatus.instance
      @collections["email"] = Email.instance
      @collections["occupation"] = Occupation.instance
      @collections["role"] = Role.instance
      @collections["locality"] = Locality.instance
      @collections["state"] = State.instance
      @collections["country"] = Country.instance
      @collections["locale_country"] = LocaleCountry.instance
      @collections["full_hometown"] = FullHometown.instance
      @collections["FullLocation"] = FullLocation.instance    
      
      @collections["music"] = Music.instance
      @collections["movies"] = Movies.instance
      @collections["interests"] = Interests.instance
      @collections["books"] = Books.instance
    end
  end 
  
end